package cn.clickmed.DaTong;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Handler;
import android.os.Message;

public class DlgWait {
	private Handler mHandler;
	private ProgressDialog pd = null;
	private InterFaceWait interFaceWait = null;
	private Thread mThread;

	@SuppressWarnings("static-access")
	public void ShowWait(Context context, String title, String msgData,
			InterFaceWait ifw) {
		mHandler = new Handler() {
			public void handleMessage(Message mesg) {
				pd.dismiss();
				mThread.interrupt();
				mThread = null;
			}
		};
		interFaceWait = ifw;
		CreateWait(context, title, msgData);
	}

	public void Close() {
		Message m = mHandler.obtainMessage();
		mHandler.sendMessage(m);
	}

	private void CreateWait(Context context, String title, String msgData) {
		pd = new ProgressDialog(context);
		pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		pd.setMessage(msgData);
		pd.setCancelable(false);
		pd.show();

		mThread = new Thread(() -> {
			interFaceWait.WaitFucn();
			Close();
		});
		mThread.start();
	}

}
